<!--头寸维护审核页面-->
<template>


  <div class="app-container" style="overflow:scroll">
    <div style="width: 1024px;margin: 20px auto">
      <el-form ref="settingsForm" :model="formData" :rules="rules" label-width="150px">
        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="交易流水号：" prop="id">
              <el-input v-model="formData.id" placeholder="交易流水号" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="12"></el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="录入操作员" prop="creater">
              <el-input v-model="formData.creater" :disabled="true" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="录入时间" prop="createddate">
              <el-date-picker
                style="width: 100%"
                v-model="formData.createddate"
                value-format="yyyyMMddHHmmss"
                type="datetime"
                :disabled="true"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="设置存款准备金余额：" prop="newreserve">
              <ht-amount-input v-model="formData.newreserve" placeholder="设置存款准备金余额" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="设置预留头寸：" prop="newposition">
              <ht-amount-input v-model="formData.newposition" placeholder="设置预留头寸" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div class="bottom-control">
        <el-button type="primary" @click="approveFn" :loading="isLoading" :disabled="isdisable">审核</el-button>
        <el-button type="warning" @click="rejectFn" :loading="isLoading" :disabled="isdisable">拒绝</el-button>
        <el-button type="primary" @click="initData" >重置</el-button>
      </div>
    </div>
  </div>

</template>
<script>
import { approve, approveDetail, reject } from "@/api/cnaps/bizMng/position.js";
import ApproveDetails from "./components/approveDetails";
import { listPageMixin } from "@/libs/listPageMixin";
import { log } from "util";
import HtAmountInput from "@/views/components/HtAmountInput";

export default {
  name: "balanceMangeApprove",
  mixins: [listPageMixin],
  components: {
    HtAmountInput,
    ApproveDetails,
  },
  data() {
    return {
      open: false,
      isLoading: false,
      isdisable: false,
      rules: {
        newreserve: [
          {
            required: true,
            message: "必填",
            trigger: "blur",
          },
        ],
        newposition: [
          {
            required: true,
            message: "必填",
            trigger: "blur",
          },
        ],
      },
      formData: {},
    };
  },
  mounted() {
    this.initData();
  },
  methods: {

    initData() {
      approveDetail().then(res => {
        this.formData = _.clone(res.result)
        if(this.formData.id===""||this.formData.id===undefined){
          this.isdisable = true;
        }else {
          this.isdisable = false;
        }
        this.$set(this.formData, "newreserve", "");
        this.$set(this.formData, "newposition", "");
      });
    },

    handleAction(type, row = {}) {
      switch (type) {
        case "detials":
          // 明细信息
          this.formData = { id: row.id };
          this.$refs.approveDetailsDialog.show();
          break;
      }
    },

    approveFn() {
      this.$refs["settingsForm"].validate((valid) => {
        if (valid) {
          this.isLoading = true;
          approve(this.formData)
            .then((res) => {
              this.isLoading = false;
              this.$emit("editComplete", true);
              this.msgSuccess("已审核!");
              this.initData();
            })
            .catch((err) => {
              this.isLoading = false;
            });
        }

      });
    },
    // 拒绝方法
    rejectFn() {
      this.$refs["settingsForm"].validate((valid) => {
        if (valid) {
          this.isLoading = true;
          reject(this.formData)
            .then((res) => {
              this.isLoading = false;
              this.$emit("editComplete", true);
              this.msgSuccess("已拒绝!");
              this.initData();
            })
            .catch((err) => {
              this.isLoading = false;
            });
        }
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.bottom-control {
  margin: 30px 0;
  text-align: center;
}
.label-header-msg {
  font-weight: bold;
}

.form-card {
  margin-bottom: 10px;
}
</style>
